//
//  DDCustomBtn.swift
//  swift微博
//
//  Created by whitcast on 16/7/19.
//  Copyright © 2016年 whitcast. All rights reserved.
//

import UIKit

class DDCustomBtn: UIButton {
    //模型
    var model: DDComposeBtnModel?{
        didSet{
            
            setTitle(model!.title, forState: .Normal)
            
            setImage(UIImage(named: model!.imgName!), forState: .Normal)

        }
    }
    //构造函数
        override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
//    override func setTitle(title: String?, forState state: UIControlState) {
//        super.setTitle(title, forState: state)
//        
//    }
    private func setupUI(){
        
        self.titleLabel?.textAlignment = .Center
        self.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(15)
//        self.adjustsImageWhenHighlighted = false
    }
    
    //  重写highlighted属性, 不重写这个属性,会面按钮放大会出现问题
    override var highlighted: Bool {
        get {
            return false
        }
        set {
            
        }
    }
    
 
    //调整子控件布局
    override func layoutSubviews() {
        super.layoutSubviews()
        imageView?.y = 0
        imageView?.x = 0
        imageView?.width = width
        imageView?.height = width
        
        titleLabel?.x = 0
        titleLabel?.y = width
        titleLabel?.width = width
        titleLabel?.height = height - width
        
        }
    
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
